#ifndef DB_H_
#define DB_H_

#include <stdexcept>
#include <sqlite3.h>
#include <sqlite3_ex.h>

namespace app {

  class DB {
    typedef int (*callback)(void*,int,wchar_t**,wchar_t**);
  public:
    static DB& instance();
    bool open(const char* path);
    void close();
    int exec(const wchar_t* sql, callback cb = nullptr, void* arg =nullptr);
    int exec(const std::wstring& sql, callback cb = nullptr, void* arg =nullptr);
  private:
    DB();
    ~DB();
    sqlite3* db_;
  };

  class bad_book : public std::domain_error {
  public:
    bad_book(const std::wstring& id);
    std::wstring id() const;
  private:
    std::wstring id_;
  };

  class bad_customer : public std::domain_error {
  public:
    bad_customer(const std::wstring& id);
    std::wstring id() const;
  private:
    std::wstring id_;
  };

}

#endif

